<template> 
  <div id="app">
    id: <input type="text" v-model="id"> 姓名： <input type="text" v-model="name"> <button @click="fun">添加</button>
    <ul>
      <!-- key的作用 -->
      <li v-for="item in arr" :key="item.id">
        <input type="checkbox">{{item.name}}
      </li>
    </ul>
  </div>
</template>

<script>
// diff =>diffrent
export default {
  name: "helloApp",
  data() {
    return {
      id: '',
      name: '',
      arr: [
        {
          id: 1,
          name: "张三"
        },
        {
          id: 2,
          name: "李四"
        },
        {
          id: 3,
          name: "王五"
        }
      ]
    }
  },
  methods: {
    fun(){
      var obj = {
        id: this.id,
        name: this.name
      }
      this.arr.unshift(obj)

    }
  }
}
</script>
<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
